﻿@model  ProductModel
@{
    ViewBag.Title = "修改产品";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<div class="path mb15">
    当前位置:<span>首页 &gt; </span><span>商品管理 &gt; </span><span>商品编辑</span>
</div>
@using (Html.BeginForm("Edit","Product",FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    <div>
    @Html.ValidationSummary(true)
    <table class="tb-form">
        <tr>
            <td class="tb-f-lable" style="width: 80px;">
                <span class="org">*</span>产品名称：
            </td>
            <td>
                @Html.TextBoxFor(x => x.Title, new { @class = "input-style-txt", @style = "width: 535px", @maxlength = "50" })
                @Html.ValidationMessageFor(x => x.Title)
                <span class="gray">最多50个字！</span>
            </td>
        </tr>
		<tr>
            <td class="tb-f-lable" style="width: 80px;">
                <span class="org">*</span>SEO关键字：
            </td>
            <td>
                @Html.TextBoxFor(x => x.SEOKeywords, new { @class = "input-style-txt", @style = "width: 535px", @maxlength = "50" })
                @Html.ValidationMessageFor(x => x.SEOKeywords)
                <span class="gray">最多100个字！</span>
            </td>
        </tr>

		<tr>
            <td class="tb-f-lable" style="width: 80px;">
                <span class="org">*</span>SEO 描述：
            </td>
            <td>
                @Html.TextBoxFor(x => x.SEODesc, new { @class = "input-style-txt", @style = "width: 535px", @maxlength = "50" })
                @Html.ValidationMessageFor(x => x.SEODesc)
                <span class="gray">最多200个字！</span>
            </td>
        </tr>

        <tr>
            <td class="tb-f-lable" style="width: 80px;">
                <span class="org">*</span>所属目录：
            </td>
            <td>
                @Html.DropDownList("ddlCategoryFirst", ViewData["Category"] as SelectList, new { onchange = "SetCategorySecond()", @size = "12", @style = "width: 180px;" })
                <select id="ddlCategorySecond" size="12" style="width: 180px;"  onchange="SetCategoryThird();">
                </select>
                <select id="ddlCategoryThird" size="12" style="width: 160px;"onchange="SetCategoryVal();">
                </select>
                @Html.HiddenFor(x => x.CategoryID)
                @Html.ValidationMessageFor(x => x.CategoryID)
            </td>
        </tr>
        <tr>
            <td class="tb-f-lable">
                <span class="org">*</span>产品图片：
            </td>
            <td>
                <input id="imgFile" name="imgFile" type="file" class="input-style-file" />  
            </td>
        </tr>
        <tr>
            <td class="tb-f-lable" style="width: 80px;">
                <span class="org">*</span>所属地区：
            </td>
            <td>
                @Html.DropDownList("Province", ViewData["Area"] as SelectList, new { onchange = "SetCity(this.value)" })省
                <select id="City" name="City" onchange = "SetAreaVal()">
                </select>市 
                 @Html.HiddenFor(x => x.AreaID)
                 @Html.ValidationMessageFor(x => x.AreaID)
            </td>
        </tr>
        <tr>
            <td class="tb-f-lable">
                <span class="org">*</span>产品概要：
            </td>
            <td>
                @Html.TextAreaFor(x => x.Summary, new { @class = "input-style-txt", @rows = "4", @cols = "100" })
                @Html.ValidationMessageFor(x => x.Summary)
                <span class="gray">最多200个字！</span>
            </td>
        </tr>
        <tr>
            <td class="tb-f-lable">
                <span class="org">*</span>产品介绍：
            </td>
            <td>
                @Html.TextAreaFor(x => x.Description, new { @class = "input-style-txt", @style = "width: 835px", @rows = "8", @cols = "100" })
                @Html.ValidationMessageFor(x => x.Description)
            </td>
        </tr>
        <tr>
            <td>
            </td>
            <td>
			    @Html.HiddenFor(x => x.ProductID);
                @Html.HiddenFor(x => x.TaoKe);

                <input type="submit" value="保存" class="i-btn5" />
            </td>
        </tr>
    </table>
</div>
}
<script type="text/javascript">
    var editor;
    KindEditor.ready(function (K) {
        editor = K.create('#Description', {
            uploadJson: '/upload/Product',
            allowFileManager: false
        });
        K('input[name=save]').click(function (e) {

            $("#Description").val(editor.html());
            $("#GetForm").submit();
        });
    });


    function SetCity(id) {
        $.get("/Area/GetCity?id=" + id, function (data) {
            generateRegionSelect(data, "City", id);
        });
    }

    function SetCategoryFirst(id) {
    	$.get('/Category/query_category_children?Pid=0',
    function (data) {
        generateSelect(data, "ddlCategoryFirst", id);
        SetCategorySecond(0);

    });
    }

    function SetCategorySecond(id) {
        var pid = $("#ddlCategoryFirst").val();
        $.get('/Category/query_category_children?Pid=' + pid,
    function (data) {
        generateSelect(data, "ddlCategorySecond", id);
        SetCategoryThird(0);
    });
    }

    function SetCategoryThird(id) {
        var pid = $("#ddlCategorySecond").val();
        $.get('/Category/query_category_children?Pid=' + pid,
    function (data) {
        generateSelect(data, "ddlCategoryThird", id);
    });
}

function SetCategoryVal() {
    var cid = $("#ddlCategoryThird").val();
    $("#CategoryID").val(cid);

}
function SetAreaVal() {
    var aid = $("#City").val();
    $("#AreaID").val(aid);
}

    /*** 生成类目中的内容*/
    function generateSelect(data, ulId, selId) {
        $("#" + ulId).empty();
        // 如果结果为成功
        var resData = data;
        for (var i = 0; i < resData.length; i++) {

            $("#" + ulId)[0].options.add(new Option(resData[i].CategoryName, resData[i].CategoryID));
        }
        if (selId > 0) {
            $("#" + ulId).attr("value", '' + selId + '');
        } else {
            $("#" + ulId)[0].selectedIndex = 0;
        }

    }

    function generateRegionSelect(data, ulId, selId) {
        $("#" + ulId).empty();
        for (var i = 0; i < data.length; i++) {

            $("#" + ulId)[0].options.add(new Option(data[i].AreaName, data[i].AreaID));

        }
        if (selId > 0) {
            $("#" + ulId).attr("value", '' + selId + '');
        } else {
            $("#" + ulId)[0].selectedIndex = 0;
        }

    }
</script>
